delphifandomcom-20200223-history
Editing the template template
Delphi Live Templates are just one of the many cool features of the BDS and Turbo IDEs. Have you wondered how to get in and tweak the template that you are presented with when you've gone through the steps required to create a new Live Template? It's not that hard, but it's one of those features, that if you don't know it's there ... it's really easy to miss. The trick is to start the IDE without a project in it. If you've already set the IDE to start up without the last project you had open -or- creating a new empty one, you are all set if not you can start the IDE using the -np command-line argument. The reason for this is, once you open a file into the IDE, you can't get at the template you need to edit. With the empty IDE up and running, open the Templates window and expand the IDE tree. There you should find a template called ... template_template. you need to select that file and click on the Edit Button on the ToolBar Right_Click and select Edit from the pop-up menu that is presented. That should have opened the file in the IDE. As I mentioned, once you open anything ... the IDE tree is no longer available in the Templates window - that includes the file you just opened. There are a number of things you can do to enhance the template so that when you create Live Templates from it, it will be a little easier or at least customized to your needs. The first thing you should do is change the delimiter used for the Live Templates created for you. You'll find that information between the innermost brackets of the item - about two thirds the way down the code block. In the output code you will find the node. You need to add a delimiter="|" parameter so that the whole thing looks like It has been noted in a number of place that leaving the delimiter in its default state of $ is a bad idea - $ can be used in code so if you don't change it and your code includes a $ it will confuse the script parser when it tries to output the code contained in your template into the IDE. The remainder of the output block can pretty well remain the same unless there are more complex changes that you would like to make. One of the enhancements you can make is to add default text to some of the data entry points. If you look further up from where we've been working you will find some nodes. Live Templates Technical Info covers these much better than I ever could except to say the ones where we're working are pretty generic. To give you an example of what can be done, I've added my name here to protect the guilty as default in the "author" point: Ima Wannabe Name of the author Because I always work with Delphi I've also changed the "language" point to: Delphi Language that the template targets Of note in the point node changes I've show above all this does is set the default values, they can easily be changed by simply typing in something new when you're in the automated mode of creating a new template. If you want to make changes that are permanent and not part of the automated process ... delete the related point node and replace the appropriate text name="whatever" parameter of the node in the output code block. Another change you might want to make is adding $end$ to the CDATA section, so your cursor doesn't stay in the Language entry point but moves on to the actual content of the template: $end$$selected$$CDATAEND$ I've also changed the output code to have all the minor nodes be single line but I won't show that here in the samples above ... bigger wars have started over much smaller things. You get the idea now. Here's a handy template you can add to your system to use when creating templates. It will automate the process of adding s to your code: Used to enter points in Live Templates Stolen from Nick Hodges who borrowed it from Deborah Pate pointname The name to be used for this point. The default text to insert. The text describing the point. <point name="|pointname|"> |*|<text>|pointtext|</text> |*|<hint>|pointhint|</hint> </point> |end| Have fun with the BDS/Turbo you've chosen to use as your programming IDE. Delphi Rocks If you want to learn more about templates and how the above works, see Live Templates Technical Info. Category:Tips and Tricks Category:Delphi IDE